package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.Clazz;
import com.rh.entity.Employee;
import com.rh.mapper.ClazzMapper;
import com.rh.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Override
    public void addMethod(Clazz clazz) {
        clazzMapper.addMethod(clazz);
    }

    @Override
    public void deleteMethod(Integer classId) {
        clazzMapper.deleteMethod(classId);
    }

    @Override
    public void updateMethod(Clazz clazz) {
        clazzMapper.updateMethod(clazz);
    }

    @Override
    public Page getClazzPage(Integer pageNo, Integer pageSize) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Clazz> methodAll =clazzMapper.getMethodAll();
        PageInfo<Clazz> info=new PageInfo<Clazz>(methodAll);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setPageCount(info.getPages());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setCount(info.getTotal());
        page.setPage(info.getList());
        return page;
    }

    @Override
    public Clazz getMethodAllById(Integer classId) {
        return clazzMapper.getMethodAllById(classId);
    }
}
